package com.itheima.demo;

public class Student001 implements Comparable<Student001> {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student001(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student001() {
    }

    @Override
    public String toString() {
        return "Student001{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student001 o) {
        int i = this.age - o.age;
        /*i = i == 0 ? this.name.compareTo(o.getName()) : i;*/
        if (i == 0) {
            i = this.name.compareTo(o.getName());
        }
        if (i == 0) {
            i = 1;
        }
        return i;
    }
}
